import datetime
from tortoise.models import Model
from tortoise import fields


class Mail(Model):
    id = fields.IntField(pk=True)
    receiver = fields.CharField(max_length=1024, description="收件人邮箱")
    subject = fields.CharField(max_length=128, description="邮件主题")
    content = fields.TextField(description="邮件正文")
    # 是否发生成功
    is_success = fields.BooleanField(default=True, description="是否成功")
    # 异常信息
    exception = fields.TextField(default="", description="异常信息")
    create_at = fields.DatetimeField(auto_now_add=True, description="创建时间")

    user = fields.ForeignKeyField(
        "models.User",
        to_field="id",
        source_field="user_id",
        null=True,
        generated=False,
    )

    class Meta:
        table = "admin_mail"
